package gentle.controller;

import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.BaseController;
import gentle.entity.QualityAssuranceInfo;
import gentle.entity.RootImageInfo;
import gentle.entity.SearchRootImageInfo;
import gentle.factory.PageFactory;
import gentle.service.IDentalImageService;
import gentle.service.IDoctorLookedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Controller
@RequestMapping("/qualityAssurances")
public class DentalImageController extends BaseController {

    @Autowired
    IDoctorLookedService doctorLookedService;

    @Autowired
    IDentalImageService dentalImageService;

    /**
     *补牙列表
     */
    @RequestMapping(value = "/getList/{reservationsId}")
    @ResponseBody
    public List<QualityAssuranceInfo> getList(@PathVariable String reservationsId) throws Exception {
        return doctorLookedService.getList(reservationsId);
    }

    /**
     * 根管影像列表
     */
    @RequestMapping(value = {"/canalList/{reservationsId}/{roleId}/{userAccount}"})
    @ResponseBody
    public Object canalList(SearchRootImageInfo info, @PathVariable(required = false)  String reservationsId,
                       @PathVariable(required = false)  String roleId, @PathVariable(required = false)  String userAccount) {
        Page<RootImageInfo> page = new PageFactory<RootImageInfo>().defaultPage();
        try {
            info.setReservationsId(reservationsId);
            info.setRoleId(roleId);
            info.setUserAccount(userAccount);
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<RootImageInfo> list = dentalImageService.selectPageListByCanal(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = dentalImageService.selectPageListByCanal(page, info);
            }
            page.setTotal(dentalImageService.getQueryPageCanalCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 洁牙影像列表
     */
    @RequestMapping(value = {"/scalingList/{reservationsId}/{roleId}/{userAccount}"})
    @ResponseBody
    public Object scalingList(SearchRootImageInfo info, @PathVariable(required = false)  String reservationsId,
                       @PathVariable(required = false)  String roleId, @PathVariable(required = false)  String userAccount) {
        Page<RootImageInfo> page = new PageFactory<RootImageInfo>().defaultPage();
        try {
            info.setReservationsId(reservationsId);
            info.setRoleId(roleId);
            info.setUserAccount(userAccount);
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<RootImageInfo> list = dentalImageService.selectPageListByScaling(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = dentalImageService.selectPageListByScaling(page, info);
            }
            page.setTotal(dentalImageService.getQueryPageScalingCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 牙周影像列表
     */
    @RequestMapping(value = {"/periodontalList/{reservationsId}/{roleId}/{userAccount}"})
    @ResponseBody
    public Object periodontalList(SearchRootImageInfo info, @PathVariable(required = false)  String reservationsId, @PathVariable(required = false)  String roleId, @PathVariable(required = false)  String userAccount) {
        Page<RootImageInfo> page = new PageFactory<RootImageInfo>().defaultPage();
        try {
            info.setReservationsId(reservationsId);
            info.setRoleId(roleId);
            info.setUserAccount(userAccount);
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<RootImageInfo> list = dentalImageService.selectPageListByPeriodontal(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = dentalImageService.selectPageListByPeriodontal(page, info);
            }
            page.setTotal(dentalImageService.getQueryPagePeriodontalCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 种植影像列表
     */
    @RequestMapping(value = {"/plantList/{reservationsId}/{roleId}/{userAccount}"})
    @ResponseBody
    public Object plantList(SearchRootImageInfo info, @PathVariable(required = false)  String reservationsId,  @PathVariable(required = false)  String roleId, @PathVariable(required = false)  String userAccount) {
        Page<RootImageInfo> page = new PageFactory<RootImageInfo>().defaultPage();
        try {
            info.setReservationsId(reservationsId);
            info.setRoleId(roleId);
            info.setUserAccount(userAccount);
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<RootImageInfo> list = dentalImageService.selectPageListByPlant(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = dentalImageService.selectPageListByPlant(page, info);
            }
            page.setTotal(dentalImageService.getQueryPagePlantCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 修复影像列表
     */
    @RequestMapping(value = {"/repairList/{reservationsId}/{roleId}/{userAccount}"})
    @ResponseBody
    public Object repairList(SearchRootImageInfo info, @PathVariable(required = false)  String reservationsId,  @PathVariable(required = false)  String roleId, @PathVariable(required = false)  String userAccount) {
        Page<RootImageInfo> page = new PageFactory<RootImageInfo>().defaultPage();
        try {
            info.setReservationsId(reservationsId);
            info.setRoleId(roleId);
            info.setUserAccount(userAccount);
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<RootImageInfo> list = dentalImageService.selectPageListByRepair(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = dentalImageService.selectPageListByRepair(page, info);
            }
            page.setTotal(dentalImageService.getQueryPageRepairCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    //获取根管 图片
    @RequestMapping(value = "/getImgcancel", method = RequestMethod.POST)
    @ResponseBody
    public List<RootImageInfo> getImgcancel(String num) throws Exception {
        return dentalImageService.getImgcancel(num);
    }

    //获取洁牙 图片
    @RequestMapping(value = "/getScalingImgcancel", method = RequestMethod.POST)
    @ResponseBody
    public List<RootImageInfo> getScalingImgcancel(String num,String iconType,String classification) throws Exception {
        return dentalImageService.getScalingImgcancel(num, iconType, classification);
    }

    //获取牙周 图片
    @RequestMapping(value = "/getPerioImgcancel", method = RequestMethod.POST)
    @ResponseBody
    public List<RootImageInfo> getPerioImgcancel(String num,String iconType,String classification) throws Exception {
        return dentalImageService.getPerioImgcancel(num, iconType, classification);
    }

    //获取种植 图片
    @RequestMapping(value = "/getPlantImgcancel", method = RequestMethod.POST)
    @ResponseBody
    public List<RootImageInfo> getPlantImgcancel(String num) throws Exception {
        return dentalImageService.getPlantImgcancel(num);
    }


    //获取修复 图片
    @RequestMapping(value = "/getRepairImgcancel", method = RequestMethod.POST)
    @ResponseBody
    public List<RootImageInfo> getRepairImgcancel(String num,String iconType,String classification) throws Exception {
        return dentalImageService.getRepairImgcancel(num, iconType, classification);
    }


}
